import { unit } from "../../api";
const MUTATION_TYPES = {
  UNIT_LIST: "UNIT_LIST",
  UNIT_SIZE: "UNIT_SIZE"
};

const state = {
  unitList: [],
  totalUnitSize: 0
};
const getters = {};

const mutations = {
  [MUTATION_TYPES.UNIT_LIST](state, unitList) {
    state.unitList = unitList;
  },
  [MUTATION_TYPES.UNIT_SIZE](state, totalUnitSize) {
    state.totalUnitSize = totalUnitSize;
  }
};

const actions = {
  async search({ commit }, filter = {}) {
    let response = await unit.search(filter);
    console.log(response);
    if (response?.code === 0) {
      commit(MUTATION_TYPES.UNIT_LIST, response.data?.records);
      // commit(MUTATION_TYPES.UNIT_SIZE, response.data?.total)
    }
  }
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
};
